home *** CD-ROM | disk | FTP | other *** search
Wrap
/* TEST PROGRAM FOR DU_LIB ©1994, Data Uncertain Software. Written by Craig Graham. ============================================================================= This program is implemented just using an event driven model. There is a main event loop rather like the normal GEM application model, but the events being waited for aren't GEM move, redraw, etc, they are things like 'text has been selected, button1 has been clicked on, quit, etc'. ============================================================================= */ #include <dulib.h> #include "test.h" /* Define some codes for events - these are arbitary integer values */ #define mev_QUIT 102 #define mev_BUTTON1 103 #define mev_BUTTON2 104 #define mev_SELTEXT 105 #define mev_OPENDIAL 106 #define mev_POPUP 107 /* This is going to be a custom redraw function. Note that as with callbacks, redraw functions are all "short nnnn(void)". A redraw should simply draw it's object - the DU_LIB will handle walking the rectangle list & setting minimal clip rectangles. */ short redy() { short x,y,rx,ry; rx=(cr_clip.g_w/2)-4; /* GRECT cr_clip contains the dimensions of the obejct we are going to redraw */ x=cr_clip.g_x+rx+2; ry=(cr_clip.g_h/2)-4; y=cr_clip.g_y+ry+2; v_ellipse(x_handle,x,y,rx,ry); /* x_handle is a vdi screen workstation handle which we can use */ /* - this workstation was opened by enviroment_initialise();*/ return 0; } short main(void) { OBJECT *o; event e; char b[200]; short inv[512]; short s; /* Setup an array of char*'s to be a popup menu */ static char *pmenu[6]={"Test Popup","one","two","three","four", "five" }; /* Setup an array of char*'s - these will be the entries in the scroll list */ static char *t[11]={"This is a demo of the", "DU_LIB GUI library for", "Lattice C.", "----------------------", "Written:[13/10/94]", "By: Craig Graham", "----------------------", "DULIB was written to", "provide a GUI for the", "other Data Uncertain ", "products."}; /* We always call the enviroment initialise function first - this will do all the appl_init() stuff */ enviroment_initialise(); /* Load in the resource file */ rsrc_load("TEST.RSC"); /* First, lets use the easy way to change text in a dialog */ set_dialog_text(My_dial, Testtext, "Testing DULIB Library"); /* Setup some events */ Set_object_event(My_menu, Menuquit, mev_QUIT); Set_object_event(My_menu, Menuopendialog, mev_OPENDIAL); Set_object_event(My_dial, Button1, mev_BUTTON1); Set_object_event(My_dial, Button2, mev_BUTTON2); Set_object_event(My_dial, Mypopup, mev_POPUP); /* Setup a test custom redraw function - usually you attach these to a box to get something in the box*/ Set_object_redraw(My_dial, Crbox, &redy); /* Initialise the scrolling list object */ Set_scroll_list(My_dial, Scrolllist, mev_SELTEXT, t, 11, 4); /* event code = mev_SELTEXT, text from t, number of items in list=11, number of items to display=4*/ /* Set a few icon popups up */ Set_icon_popup(My_dial, Popup1, Gateiconpopup); Set_icon_popup(My_dial, Popup2, Gateiconpopup); /* Set up the menu bar*/ install_menu(My_menu); /* Configure resources to monochrome if we aren't a colour machine. */ /* enviroment_initialise() always opens a vdi virtual workstation to the screen, */ /* with the handle 'x_handle', so I use that for my screen display work. */ vq_extnd(x_handle,0,inv); if (inv[13]<16) rsrc_form2mono(My_dial, 3); /* Convert the dialog into mono if we need to (ie, we don't have 16 colours) */ /* Open the dialog */ activate_dialog(My_dial,"DULIB: EVENTS TEST",DIAL_ROLLUP); do { e=WaitEvent(); /* The all important call. This replaces event_multi */ switch (e) { case mev_SELTEXT: sprintf(b,"[1][ SCROLL TEXT SELECTED : | '%s' | ][ OK ]",t[scroll_selection]); form_alert(1,b); break; case mev_OPENDIAL: activate_dialog(My_dial,"DULIB TEST DIALOG",DIAL_ROLLUP); break; case mev_BUTTON1: DU_mode(DU_MODE_RIGHT_EQUALS_DOUBLE,TRUE); form_alert(1,"[1][ BUTTON 1 SELECTED | Right Mouse Button now | equals double click ][ OK ]"); break; case mev_BUTTON2: DU_mode(DU_MODE_RIGHT_EQUALS_DOUBLE,FALSE); form_alert(1,"[1][ Right Mouse Button Ignored | (button 2) | ][ spam? ]"); break; case mev_POPUP: /* call form_popup(), for 5 items (remember, item 0 is the popup's title line), with no default selection */ s=form_popup(My_dial,Mypopup, 5, 0, pmenu); /* set the text in the dialog to show which option was selected from the popup */ set_dialog_text(My_dial,Mypopup, pmenu[s]); rsrc_gaddr(0,My_dial,&o); objc_draw(o,Mypopup,1,scrn_x,scrn_y,scrn_w,scrn_h); break; } } while (e!=mev_QUIT); rsrc_free(); close_down(); return 0; }